package com.wonder.web;

import com.wonder.dao.UserRepository;
import com.wonder.domain.User;
import com.wonder.dto.ResponseMsgDto;
import com.wonder.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by tmac9 on 2017/6/8.
 */

@Controller
@RequestMapping(value="user")
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping(value="login")
    @ResponseBody
    public ResponseMsgDto login(HttpServletRequest request){
        HttpSession session = request.getSession();
        ResponseMsgDto res = new ResponseMsgDto();
        User user = userService.login("admin","admin");
        if(null != user){
            session.setAttribute("user",user);
            res.setStatus(true);
            user.setPassword(null);
            res.setMsg(user);
        }else{
            res.setStatus(false);
        }
        return res;

    }
}
